package com.ruoyi.web.controller.activeinfo;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activeinfo.domain.ActiveInfo;
import com.ruoyi.activeinfo.service.IActiveInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区活动Controller
 * 
 * @author hct
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/activeinfo/activeinfo")
public class ActiveInfoController extends BaseController
{
    @Autowired
    private IActiveInfoService activeInfoService;

    /**
     * 查询社区活动列表
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActiveInfo activeInfo)
    {
        startPage();
        List<ActiveInfo> list = activeInfoService.selectActiveInfoList(activeInfo);
        return getDataTable(list);
    }

    /**
     * 导出社区活动列表
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:export')")
    @Log(title = "社区活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActiveInfo activeInfo)
    {
        List<ActiveInfo> list = activeInfoService.selectActiveInfoList(activeInfo);
        ExcelUtil<ActiveInfo> util = new ExcelUtil<ActiveInfo>(ActiveInfo.class);
        util.exportExcel(response, list, "社区活动数据");
    }

    /**
     * 获取社区活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(activeInfoService.selectActiveInfoById(id));
    }

    /**
     * 新增社区活动
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:add')")
    @Log(title = "社区活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActiveInfo activeInfo)
    {
        activeInfo.setCollectNum(0);
        activeInfo.setViewNum(0);
        activeInfo.setCreateTime(new Date());
        activeInfo.setCreateBy(getUsername());
        return toAjax(activeInfoService.insertActiveInfo(activeInfo));
    }

    /**
     * 修改社区活动
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:edit')")
    @Log(title = "社区活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActiveInfo activeInfo)
    {
        activeInfo.setUpdateTime(new Date());
        activeInfo.setUpdateBy(getUsername());
        return toAjax(activeInfoService.updateActiveInfo(activeInfo));
    }

    /**
     * 删除社区活动
     */
    @PreAuthorize("@ss.hasPermi('activeinfo:activeinfo:remove')")
    @Log(title = "社区活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activeInfoService.deleteActiveInfoByIds(ids));
    }
}
